<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>京东订单查询</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }

    :focus {
        outline: none;
    }

    .search {
        position: relative;
        width: 178px;
        margin: 100px;
        background-color: aqua;
    }

    .search input {
        height: 32px;
        padding-left: 5px;
    }

    .con {
        /* 先隐藏 */
        /* display: block; */
        display: none;
        position: absolute;
        top: -50px;
        width: 171px;
        border: 1px solid rgba(0, 0, 0, .2);
        box-shadow: 0 2px 4px rgba(0, 0, 0, .2);
        padding: 10px 0;
        font-size: 18px;
        line-height: 20px;
        color: #333;
        padding-left: 5px;

    }

    .con::before {
        content: '';
        width: 0;
        height: 0;
        position: absolute;
        top: 38px;
        left: 18px;
        border: 8px solid #000;
        border-style: solid dashed dashed;
        border-color: #fff transparent transparent;
    }
</style>

<body>
    <div class="search">
        <div class="con"></div>
        <input type="text" placeholder="请输入您的快递单号" class="jd">
    </div>

    <script>
        var ips = document.getElementsByClassName('jd')[0]
        var dis = document.getElementsByClassName('con')[0]

        console.log(ips, dis);


        // 按键事件
        ips.onkeyup = function (e) {
            if (ips.value == '') {
                dis.style.display = 'none';
            } else {
                dis.style.display = 'block'
                dis.innerHTML = ips.value
            }

        }
        //监听是否失焦
        ips.addEventListener('blur', function () {
            dis.style.display = 'none'
        })

        //监听获焦
        ips.addEventListener('focus', function () {
            if (this.value == '') {
                dis.style.display = 'none';
            } else {
                dis.style.display = 'block'
            }
        })

    </script>
</body>

</html>